package com.xintonghua.bussiness.ui.fragment.client;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.xintonghua.base.utils.DividerItemDecoration;
import com.xintonghua.base.utils.MyUtils;
import com.xintonghua.base.utils.RefreshUtils;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.adapter.ProductAdapter;
import com.xintonghua.bussiness.api.HttpCent;
import com.xintonghua.bussiness.base.BaseActivity;
import com.xintonghua.bussiness.bean.BackTypeBean;
import com.xintonghua.bussiness.ui.home.SettlementActivity;
import com.xintonghua.bussiness.util.AbstractBaseAdapter;
import com.xintonghua.bussiness.util.JumpUtils;
import com.xintonghua.bussiness.util.MyState;
import com.xintonghua.bussiness.util.ViewHolder;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liqi on 2018/3/29.
 * <p>
 * 存储模板到
 * R.layout.activity_save_mode_to
 */
public class SaveModeToActivity extends BaseActivity {

    @BindView(R.id.slistview)
    ListView slistview;
    List<BackTypeBean> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_save_mode_to);
        ButterKnife.bind(this);
        list = (List<BackTypeBean>) JumpUtils.getSerializable(this);
        initUI();
    }

    AbstractBaseAdapter adapter;

    @Override
    public void dataBack(Object data, int order) {
        super.dataBack(data, order);
        try {
            switch (order) {
                case MyState.requestFour:
                    MyUtils.mToast(SaveModeToActivity.this, "模板信息保存成功");
                    finish();
                    break;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void initUI() {
        super.initUI();
        onSimpleActionBar();
        setSimpleActionBar("保存模板到");

        slistview.setAdapter(adapter = new AbstractBaseAdapter<BackTypeBean>(list) {
            @Override
            public View getAdapterViewAtPosition(int position, View convertView, ViewGroup parent) {

                if (convertView == null) {
                    convertView = LayoutInflater.from(SaveModeToActivity.this).inflate(R.layout.activity_customers, null);
                }
                BackTypeBean bean = getItem(position);
                TextView tv_type = ViewHolder.get(convertView, R.id.tv_type);
                TextView tv_numbers = ViewHolder.get(convertView, R.id.tv_numbers);
                tv_type.setText("" + bean.getName() + ":");
                tv_numbers.setText("");
                return convertView;
            }
        });
        slistview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                String content = JumpUtils.getString(SaveModeToActivity.this, "content");
                HttpCent.getInstance(SaveModeToActivity.this).saveModeTo(list.get(i).getId(), content, SaveModeToActivity.this, MyState.requestFour);
            }
        });
    }
}
